/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Pruebas;

import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Bryan
 */
public class Sistem_Tray extends javax.swing.JFrame {

    /**
     * Creates new form Sistem_Tray
     */
    PopupMenu pum_menu = new PopupMenu();
    Image imagen_pequeña = new ImageIcon(getClass().getResource("/imagenes/icon.png")).getImage().getScaledInstance
            (16, 16, java.awt.Image.SCALE_SMOOTH );
    TrayIcon trayIcon = new TrayIcon(imagen_pequeña, "Pruebas", pum_menu);
    public Sistem_Tray ()
    {
        initComponents();
        if ( SystemTray.isSupported())
          {
            SystemTray tray = SystemTray.getSystemTray();
            // mouse
            MouseListener lector_raton = new MouseListener() {

                  @Override
                  public void mouseClicked (MouseEvent e)
                  {
                      if ( e.getButton()==MouseEvent.BUTTON1 && Sistem_Tray.getFrames()[0].getExtendedState()==JFrame.ICONIFIED )
                        {
                          
                        }
                      else if(e.getButton()==MouseEvent.BUTTON1 && !(Sistem_Tray.getFrames()[0].getExtendedState()==JFrame.ICONIFIED)){
                          trayIcon.displayMessage("ATENCIÓN", "La aplicación no esta minmizada", TrayIcon.MessageType.WARNING);
                      }
                  }

                  @Override
                  public void mousePressed (MouseEvent e)
                  {
                     
                  }

                  @Override
                  public void mouseReleased (MouseEvent e)
                  {
                      
                  }

                  @Override
                  public void mouseEntered (MouseEvent e)
                  {
                     
                  }

                  @Override
                  public void mouseExited (MouseEvent e)
                  {
                     
                  }
              };
            // menu items
            MenuItem item1 = new MenuItem("Cosas");
            item1.addActionListener(new ActionListener() {

                  @Override
                  public void actionPerformed (ActionEvent e)
                  {
                     JOptionPane.showMessageDialog(Sistem_Tray.getFrames()[0], "Va bien");
                  }
              });
            //añadir menuitems al popup
            pum_menu.add(item1);
            trayIcon.setPopupMenu(pum_menu);
            //final
            trayIcon.addMouseListener(lector_raton);
              try
                {
                  tray.add(trayIcon);
                } catch (Exception e)
                {
                }
            
          }
    }
    public void MensajeTray(String mensaje, TrayIcon.MessageType tipoMessageType){
        
    }
    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 462, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 373, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main (String args[])
    {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel.
         * For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try
          {
            for ( javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels() )
              {
                if ( "Nimbus".equals(info.getName()) )
                  {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                  }
              }
          } catch (ClassNotFoundException ex)
          {
            java.util.logging.Logger.getLogger(Sistem_Tray.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (InstantiationException ex)
          {
            java.util.logging.Logger.getLogger(Sistem_Tray.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (IllegalAccessException ex)
          {
            java.util.logging.Logger.getLogger(Sistem_Tray.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (javax.swing.UnsupportedLookAndFeelException ex)
          {
            java.util.logging.Logger.getLogger(Sistem_Tray.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run ()
            {
                new Sistem_Tray().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    // End of variables declaration//GEN-END:variables
}
